spike(stark): builder-rewrite (Plan B) constraint capture → IR [compare vs #737]#739
Draft
MauroToscano wants to merge 2 commits into
Draft
spike(stark): builder-rewrite (Plan B) constraint capture → IR [compare vs #737]#739MauroToscano wants to merge 2 commits into
MauroToscano wants to merge 2 commits into
Conversation
…nts into the IR Counterpart to PR #737 (symbolic field) for comparing the two capture front-ends. Reuses the same IR + CPU interpreter; adds an explicit IrBuilder + object-safe Capture trait, with capture() implemented on IsBit/Add/ProductZero ALONGSIDE their unchanged evaluate (non-destructive). Diff test matches real evaluate bit-for-bit over 1000 random rows; captured node counts 4-21 (vs A's 66-78, since the builder only emits leaves for columns actually read). CPU-only minimal spike, same scope as #737.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Plan B (explicit builder rewrite) for capturing transition constraints into a flat IR —
the counterpart to #737 (Plan A, symbolic field), so the two capture approaches can be
compared side by side. Same motivation: get constraint eval onto the GPU to keep the prove
pipeline data-resident (avoid round-tripping the LDE trace off-device).
Both PRs produce the same IR and use the same interpreter — they differ only in the
capture front-end:
evaluateover
SymFieldrecords the IR. Zero constraint-body edits, but leaves a fakeIsField(
unimplemented!()stubs,eq → false) + a thread-local arena in the codebase.IrBuilder+ per-constraintcapture(&mut IrBuilder). Nofake field, no arena; each constraint spells out its IR. Cost: rewriting constraint bodies.
What's in it
New module
crypto/stark/src/constraint_ir/:ir.rs,interp.rs— reused verbatim from the Plan A spike (the IR types + CPUinterpreter are identical across approaches).
builder.rs—IrBuilder(hash-conses nodes on(Op, Dim), dedups base constants byvalue, dim-join
(D1,D1)->D1elseD3) +Expr { id, dim }.mod.rs— object-safeCapture { fn capture(&self, &mut IrBuilder); }trait.Constraint
captureimpls (added alongside the existingevaluate, which is untouched —non-destructive, so the old path stays as the diff oracle):
IsBitConstraint,AddConstraint(incl.AddOperand/AddLinearTermlo/hi-limb mapping with i64 coeffs andthe
inv_2_32constant),ProductZeroConstraint.Test (
prover/src/tests/constraint_ir_tests.rs): same scope and structure as #737 — captureseach constraint via the builder and asserts the IR interpreter matches the real
evaluatebit-for-bit over 1000 random rows.
Results
stark+lambda-vm-proverbuild;cargo fmt/clippyclean (no new warnings).cargo test -p lambda-vm-prover constraint_ir_tests.add_carry_0 14, add_carry_1 21 — much smaller than A's 66–78, because the builder
only emits leaves for columns actually read (A padded 64 unused column leaves). add_carry_1
reuses the whole carry_0 subtree via CSE.
A vs B — what to compare
capture()(here: 3 structs; full set = ~33)IsField+ thread-local arenaevaluate)Scope / follow-ons (same as #737)
Minimal CPU-only spike: base-field algebraic constraints, main columns, single step. Out of
scope: LogUp constraints, aux/next-row, wiring into
evaluate_transitions, and the GPU kernel.Design docs + the full phased plan live in #737 (
thoughts/gpu-constraint-eval/).Draft / spike — not for merge as-is; this exists so we can pick A vs B before scaling to the
full constraint set.